package com.aclass.xqx.classscreen.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aclass.xqx.classscreen.R;
import com.aclass.xqx.classscreen.db.CardStudent;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by xqx on 2017/10/25.
 * 进步学习之星adapter
 */

public class NameAdapter extends RecyclerView.Adapter<NameAdapter.ViewHolder>  {
    private Context mContext;
    private List<CardStudent> list;
    private ImageView iv;
    private TextView tv_name;

    public NameAdapter(Context mContext, List<CardStudent> list) {
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =
                LayoutInflater.from(parent.getContext()).inflate(R.layout.nameitem, parent, false);
        return new NameAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        View view = holder.mView;
        iv= (ImageView) view.findViewById(R.id.iv_name);
        tv_name= (TextView) view.findViewById(R.id.tv_name);
        Log.e("ATG 时间",position+"");
            setcontent(position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder  extends RecyclerView.ViewHolder{
        public final View mView;
        public ViewHolder(View view) {
            super(view);
            mView = view;
        }
    }
    public void setcontent(int i){
        String url=list.get(i).getStudent_url();
        String name=list.get(i).getStudent_name();
        tv_name.setText(name);
        if (url.equals("无头像")){
            iv.setImageResource(R.mipmap.student);
        }else {
            Glide.with(mContext).load(url).into(iv);
        }
    }
}
